package cn.edu.sdjzu.xg11.dao;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

import org.springframework.stereotype.Repository;

import cn.edu.sdjzu.xg11.domain.Department;
import cn.edu.sdjzu.xg11.domain.GraduateProject;
import cn.edu.sdjzu.xg11.domain.GraduateProjectStatus;
import cn.edu.sdjzu.xg11.domain.Major;
import cn.edu.sdjzu.xg11.domain.ProjectCategory;
import cn.edu.sdjzu.xg11.domain.ProjectType;
import cn.edu.sdjzu.xg11.domain.Teacher;
@Repository
public final class GraduateProjectDao {
	private static GraduateProjectDao graduateProjectDao = new GraduateProjectDao();
	static Set<GraduateProject> projects;
	static {		
				
		Department misDepartment = new DepartmentDao().getDepartment(2);
		
		Major misMajor = MajorDao.getInstance().getMajor(1);
		Major ieMajor = MajorDao.getInstance().getMajor(2);
		
		
		Teacher stg = TeacherDao.getInstance().getTeacher(1);
		Teacher lx = TeacherDao.getInstance().getTeacher(2);
		
		
		ProjectCategory design = ProjectCategoryDao.getInstance().getProjectCategory(1);
		ProjectCategory thesis = ProjectCategoryDao.getInstance().getProjectCategory(2);
		
		ProjectType real = new ProjectTypeDao().getProjectType(1);
		ProjectType virtual = new ProjectTypeDao().getProjectType(2);
		
		Set<Major> limitedMajors = new HashSet<Major>();
		limitedMajors.add(misMajor);
		limitedMajors.add(ieMajor);
		
		GraduateProjectStatus suppendStatus = 
			GraduateProjectStatusDao.getInstance().getGraduateProjectStatus(1);
		
		GraduateProject project1 = new GraduateProject("XX项目管理信息系统的设计与实现",limitedMajors,design,real,suppendStatus,stg);
		GraduateProject project2 = new GraduateProject("虚拟现实中碰撞处理的研究",limitedMajors,thesis,virtual,suppendStatus,stg);
		GraduateProject project3 = new GraduateProject("某高校监考管理系统的设计与实现",limitedMajors,design,real,suppendStatus,stg);
		GraduateProject project4 = new GraduateProject("网上教学平台的设计与实现",limitedMajors,design,real,suppendStatus,lx);
	
		projects = new TreeSet<GraduateProject>();
		projects.add(project1);
		projects.add(project2);
		projects.add(project3);
		projects.add(project4);
	}
	
	private GraduateProjectDao(){}
	
	public static GraduateProjectDao getInstance(){
		return graduateProjectDao;
	}
	
	public Collection<GraduateProject> getGraduateProjects(){
		return projects;
	}
	public void addGraduateProject(GraduateProject project){
		projects.add(project);
	}
	public void updateGraduateProject(GraduateProject project){
		projects.remove(project);
		this.addGraduateProject(project);
	}
	
	public void deleteGraduateProject(GraduateProject graduateProject){
		projects.remove(graduateProject);		
	}
	public void deleteGraduateProject(Integer id){
		projects.remove(new GraduateProject(id));		
	}
	
	public GraduateProject getGraduateProject(Integer id) {
		GraduateProject desiredGraduateProject = null;
		for (GraduateProject graduateProject : projects) {
			if(id.equals(graduateProject.getId())){
				desiredGraduateProject =  graduateProject; 
				break;
			}
		}
		return desiredGraduateProject;
		
	}
	
}
